<?php
    session_start();
//    echo "Login: ".$_SESSION["userID"]." ".$_SESSION["userType"];

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    if(isset($_SESSION["userID"]) && !strcmp($_SESSION["userType"], "manager")){
    $userType = $_GET["userType"];
    
    $con = mysql_connect("localhost", "zhouzhao", "19831022");
    if(!$con){
        die("could not connect to DB: ".mysql_error());
    }
    
    mysql_selectdb("cloudcom", $con);
    
    $sql = "select * from users";
    
    if(!strcmp($userType, "administrator")){
        $sql = $sql." where userType='$userType'";
    }else if(!strcmp($userType, "seller")){
        $sql = $sql." where userType='$userType'";
    }else if(!strcmp($userType, "manager")){
        $sql = $sql." where userType='$userType'";
    }
    
    $result = mysql_query($sql);
    
    echo "query: $sql";
    echo "<table border='1' id='userTable'>
    <tr>
        <th>Username</th>
        <th>Password</th>
        <th>First name</th>
        <th>Last name</th>
        <th>DOB</th>
        <th>User type</th>
    </tr>";
        
    while($row = mysql_fetch_assoc($result)){
        echo "<tr>";
        echo "<td>".$row["username"]."</td>";
        echo "<td>".$row["password"]."</td>";
        echo "<td>".$row["firstName"]."</td>";
        echo "<td>".$row["lastName"]."</td>";
        echo "<td>".$row["dob"]."</td>";
        echo "<td>".$row["userType"]."</td>";
        echo "</tr>";
    }
    echo "</table>";
    }else{
        require 'login.html';
    }
?>
